<template>
	<view>
		<uni-section title="选择环境" type="line">
			<view class="wrapper">
				<uni-data-checkbox v-model="selEnv" :localdata="envs"></uni-data-checkbox>
			</view>
			<view>
				<button type="primary" @click="save()">确定</button>
			</view>
		</uni-section>
	</view>
</template>

<script>
	
	import * as Constant from "@/utils/constant.js";
	import * as env from '@/env.js';
	
	
	
	export default {
 
		data() {
			return {
				selEnv:1,
				envs:[
					{text:'DEV环境',value:0},
					{text:'UAT环境',value:1},
					{text:'PROD环境',value:2}
				]
			};
		},
		onLoad(options) {
			const savedEnv = uni.getStorageSync('env');
			
			if(savedEnv.name=='DEV'){
				this.selEnv=0;
			}else if(savedEnv.name=='UAT'){
				this.selEnv=1;
			}else{
				this.selEnv=2;
			}
		},
		onUnload() {
		  
		},
		methods:{
			save(){
				if(this.selEnv==0){
					env.default.baseUrl="http://localhost:8181";
					env.default.baseWs="ws://localhost:8181";
					env.default.clientId='uds';
					env.default.name='DEV';
				}
				else if(this.selEnv==1){
					//UAT
					env.default.baseUrl="http://106.15.224.125:9191";
					env.default.baseWs="ws://106.15.224.125:9191";
					env.default.clientId='uds';
					env.default.name='UAT';
					
				}else{
					//PROD
					env.default.baseUrl="https://api.qy-cloud.cn";
					env.default.baseWs="wss://api.qy-cloud.cn";
					env.default.clientId='uds-prod';
					env.default.name='PROD';
				}
				
				uni.setStorageSync('env',env.default);
				
				uni.navigateBack();
			}
		}
 
	}
</script>

 

<style lang="scss">
	
	.wrapper{
		padding-left: 20rpx;
		margin-bottom: 20rpx;
	}
 
</style>
